package com.dongpl.annotation.anno;

import cn.hutool.core.util.StrUtil;
import com.dongpl.annotation.IsMobile;
import com.dongpl.utils.PhoneUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ValidateMobile implements ConstraintValidator<IsMobile,String> {

    @Override
    public void initialize(IsMobile constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if (StrUtil.isNotBlank(value)) {
            return PhoneUtil.checkPhone(value);
        } else {
            return false;
        }
    }
}
